package com.starsola.servlet;

import com.starsola.util.ContentText;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ContentText.setVal(ContentText.METHOD, "get");
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean bool = isBool(req);
        resp.setContentType("text/html;charset=UTF-8");
        String val = ContentText.getVal(ContentText.METHOD);
        if (val != null) {
            resp.getWriter().print("<h1>Hello World get请求</h1>" +bool);
            return;
        }
        resp.getWriter().print("<h1>Hello World Post请求</h1>" + bool);
    }

    private boolean isBool(HttpServletRequest req) {
        String username = req.getParameter("username");
        String txt = req.getParameter("txt");
        System.out.println(txt);
        return username.equals("123");
    }
}
